package com.demo.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.demo.common.dto.PageDTO;
import com.demo.entity.Role;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "角色表查询条件")
public class RoleQueryDTO extends PageDTO {

    @Schema(description = "角色名")
    private String name;

    @Schema(description = "创建时间开始")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTimeStart;

    @Schema(description = "创建时间结束")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTimeEnd;

    public LambdaQueryWrapper<Role> buildQueryWrapper() {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(this.getName())) {
            queryWrapper.like(Role::getName, this.getName());
        }
        if (this.getCreateTimeStart() != null) {
            queryWrapper.ge(Role::getCreateTime, this.getCreateTimeStart());
        }
        if (this.getCreateTimeEnd() != null) {
            queryWrapper.le(Role::getCreateTime, this.getCreateTimeEnd());
        }
        return queryWrapper;
    }
}